package com.cjkj.system.service.impl;

import com.cjkj.common.core.utils.DateUtils;
import com.cjkj.system.api.domain.THospitalDept;
import com.cjkj.system.api.domain.THospitalUser;
import com.cjkj.system.api.domain.THospitalUserOperLog;
import com.cjkj.system.domain.THospitalInfo;
import com.cjkj.system.mapper.THospitalDeptMapper;
import com.cjkj.system.mapper.THospitalInfoMapper;
import com.cjkj.system.mapper.THospitalUserMapper;
import com.cjkj.system.mapper.THospitalUserOperLogMapper;
import com.cjkj.system.service.ITHospitalUserOperLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 医院用户操作日志记录Service业务层处理
 * 
 * @author cjkj
 * @date 2024-08-30
 */
@Service
public class THospitalUserOperLogServiceImpl implements ITHospitalUserOperLogService 
{
    @Resource
    private THospitalUserOperLogMapper tHospitalUserOperLogMapper;

    @Resource
    private THospitalUserMapper hospitalUserMapper;

    @Resource
    private THospitalInfoMapper hospitalInfoMapper;

    @Resource
    private THospitalDeptMapper hospitalDeptMapper;

    /**
     * 查询医院用户操作日志记录
     * 
     * @param operId 医院用户操作日志记录主键
     * @return 医院用户操作日志记录
     */
    @Override
    public THospitalUserOperLog selectTHospitalUserOperLogByOperId(Long operId)
    {
        return tHospitalUserOperLogMapper.selectTHospitalUserOperLogByOperId(operId);
    }

    /**
     * 查询医院用户操作日志记录列表
     * 
     * @param tHospitalUserOperLog 医院用户操作日志记录
     * @return 医院用户操作日志记录
     */
    @Override
    public List<THospitalUserOperLog> selectTHospitalUserOperLogList(THospitalUserOperLog tHospitalUserOperLog)
    {
        return tHospitalUserOperLogMapper.selectTHospitalUserOperLogList(tHospitalUserOperLog);
    }

    /**
     * 新增医院用户操作日志记录
     * 
     * @param tHospitalUserOperLog 医院用户操作日志记录
     * @return 结果
     */
    @Override
    public int insertTHospitalUserOperLog(THospitalUserOperLog tHospitalUserOperLog)
    {
        // 操作时间
        tHospitalUserOperLog.setOperTime(DateUtils.getNowDate());

        String operName = tHospitalUserOperLog.getOperName();
        THospitalUser hospitalUser = hospitalUserMapper.selectTHospitalUserByUserName(operName);
        if(hospitalUser != null) {
            // 医院名称
            THospitalInfo tHospitalInfo = hospitalInfoMapper.selectTHospitalInfoByHospitalId(hospitalUser.getHospitalId());
            tHospitalUserOperLog.setHospitalName(tHospitalInfo == null ? "" : tHospitalInfo.getHospitalName());

            // 科室名称
            THospitalDept tHospitalDept = hospitalDeptMapper.selectTHospitalDeptByDeptId(hospitalUser.getDeptId());
            tHospitalUserOperLog.setDeptName(tHospitalDept == null ? "" : tHospitalDept.getDeptName());
        }

        return tHospitalUserOperLogMapper.insertTHospitalUserOperLog(tHospitalUserOperLog);
    }

    /**
     * 修改医院用户操作日志记录
     * 
     * @param tHospitalUserOperLog 医院用户操作日志记录
     * @return 结果
     */
    @Override
    public int updateTHospitalUserOperLog(THospitalUserOperLog tHospitalUserOperLog)
    {
        return tHospitalUserOperLogMapper.updateTHospitalUserOperLog(tHospitalUserOperLog);
    }

    /**
     * 批量删除医院用户操作日志记录
     * 
     * @param operIds 需要删除的医院用户操作日志记录主键
     * @return 结果
     */
    @Override
    public int deleteTHospitalUserOperLogByOperIds(Long[] operIds)
    {
        return tHospitalUserOperLogMapper.deleteTHospitalUserOperLogByOperIds(operIds);
    }

    /**
     * 删除医院用户操作日志记录信息
     * 
     * @param operId 医院用户操作日志记录主键
     * @return 结果
     */
    @Override
    public int deleteTHospitalUserOperLogByOperId(Long operId)
    {
        return tHospitalUserOperLogMapper.deleteTHospitalUserOperLogByOperId(operId);
    }
}
